<?php
/**
 * Created by PhpStorm.
 * User: Antique
 * Date: 2021/12/6
 * Time: 下午 08:25
 */
namespace test;

use test\primary\mate_cookie;
use test\primary\sql_action;

include 'primary\sql_action.php';
include 'primary\mate_cookie.php';

$mate_cookie=new mate_cookie();
$pd= $mate_cookie->mate();
$md5=$_COOKIE['Token'];
$arr=$_SESSION[$md5];
$img_name='';
if($pd==0){
$life=$arr['life'];
$username=$arr['username'];
$conn=new \mysqli();
$conn->connect('127.0.0.1', 'root', '123456', 'userinfo');
    if (!empty($conn->connect_error)) {
        echo '数据库开启异常，请重试';
        die;
    }
    sql_action::set_conn($conn);
    $sql=('select head_portrait,head_portrait_type from user_info where cookie=\''.$md5.'\'');
    $data= sql_action::select_get_data($sql);
    if(!empty($data['head_portrait'])){
        $img_name='img/'.$data['head_portrait'].'.'.$data['head_portrait_type'];
    }
}
$date=date('Y年m月d日-h时i分s秒',$life);
?>
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="./css/login_css1.css"/>
	<body id="body1">
		<h1>用户中心</h1>
		<h2>欢迎你：
			<?php echo $username ?>
		</h2>
        <img id="img1" class="head_portrait_show" src="<?php echo $img_name ?>" /><br>
		<small>cookie到期时间:
			<?php echo $date ?></small>
		<form action="primary/head_portrait.php" name="form1" method="post" enctype="multipart/form-data">
			<input type="file" name="head_img" id="ipt1" onchange="imgshow()" value="选择头像" />
			<input type="submit" name="" id="" value="提交头像" /><br>
			<br />
		</form>
        <button onclick="login_out()">退出登录</button>
        &nbsp &nbsp &nbsp &nbsp
            <button type="button" onclick="change_pwd()">修改密码</button>
	</body>

	<script type="text/javascript" id="">
		var img1_ = document.getElementById('img1');
		var ipt1_ = document.getElementById('ipt1');
		switch (<?php echo $pd ?>) {
			case 1:
				alert('你还没登陆或者cookie失效');
				window.location.href = 'login.php';
				break;
			case 2:
				alert('cookie匹配失败');
				window.location.href = 'login.php';
				break;
			case 3:
				alert('cookie到期');
				window.location.href = 'login.php';
				break;
		}

		function imgshow() {
			var files = ipt1_['files'];
			var url = window.URL;
			var imgurl = url.createObjectURL(files[0]);
			img1_.src = imgurl;
			img1_.style.width = '30px';
		}
		function change_pwd() {
            window.location.href='primary/change_pwd.php';
        }
        function login_out(){
        window.location.href='primary/login_out.php';
        }
	</script>

</html>
